/**
 * 登陆JS
 */
$(function(){
	
	var basePath = $("#basePath").val();
	
	var $loginForm = $("#myForm");
	var $username = $("#username");
	var $password = $("#password");
	var $imgCode = $("#imgCode");
	var $isRememberUsername = $("#isRememberUsername");
		
	// 记住用户名
	if($.cookie("rmbUser") == "true") {
		$isRememberUsername.prop("checked", true);
		$username.val($.cookie("adminUsername"));
		$password.val($.cookie("password"));
		$password.focus();
	} else {
		$isRememberUsername.prop("checked", false);
		$username.focus();
	}

	// 表单验证、记住用户名
	$loginForm.submit( function() {
		if ($username.val() == "") {
			layer.msg("请输入用户名",{icon:2});
			$("#imgId").attr('src',basePath+"/imageCode?date="+new Date().getTime());
			return false;
		}
		if ($password.val() == "") {
			layer.msg("请输入密码",{icon:2});
			$("#imgId").attr('src',basePath+"/imageCode?date="+new Date().getTime());
			return false;
		}
		if($imgCode.val() == ""){
			layer.msg("请输入验证码",{icon:2});
			$("#imgId").attr('src',basePath+"/imageCode?date="+new Date().getTime());
			return false;
		}
		
		if ($isRememberUsername.prop("checked")) {
			$.cookie("rmbUser", "true", {path:"/",expires: 7 }); //存储一个带7天期限的cookie
			$.cookie("adminUsername", $username.val(),{path:"/",expires: 7});
			$.cookie("password", $password.val(), { path:"/",expires: 7 });
		} else {
			//removeCookie("adminUsername");
		    $.cookie("rmbUser", "false", { path:"/",expire: -1 });
            $.cookie("adminUsername", "", {path:"/", expires: -1 });
            $.cookie("password", "", {path:"/", expires: -1 });
		}
	});
});

/**
 * 看不清图片
 * @param url
 */
function changImg(url){
	$("#imgId").attr('src',url+"?date="+new Date().getTime());
}